package com.antdsp.web.dto;

import com.antdsp.data.entity.system.SystemTagDef;
import com.antdsp.utils.TreeNodeVO;
import com.antdsp.utils.TreeUtil;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class TagTree extends TreeNodeVO<TagTree> {

    private Long tagId;

    private Long parentId;

    private String tagName;

    private List<TagTree> children;

    private Integer orderNum;

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public Long getTagId() {
        return tagId;
    }

    public void setTagId(Long tagId) {
        this.tagId = tagId;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getTagName() {
        return tagName;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }

    public List<TagTree> getChildren() {
        return children;
    }

    public void setChildren(List<TagTree> children) {
        this.children = children;
    }

    public void appendChildren(TagTree childMen) {
        if(children == null) {
            children = new ArrayList<>();
        }
        children.add(childMen);
    }

    public static List<TagTree> buildTree(List<SystemTagDef> menus, String root) {
        List<TagTree> trees = new ArrayList<>();
        TagTree node = null;
        for (SystemTagDef tag : menus) {
            node = new TagTree();
            BeanUtils.copyProperties(tag, node);
            //node.setValue(menu.getId());
            //node.setLabel(menu.getTitle());
            trees.add(node);
        }
        return TreeUtil.build(trees, root) ;
    }
}
